package ru.spbu.mm.diploma.common.facade;

import ru.spbu.mm.diploma.common.entity.Risk;
import ru.spbu.mm.diploma.common.entity.RiskGroup;
import ru.spbu.mm.diploma.common.resources.RiskOverview;
import ru.spbu.mm.diploma.server.dao.DAOBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Ksushenka
 * Date: 30.10.11
 * Time: 14:10
 * To change this template use File | Settings | File Templates.
 */
public class RiskFacadeImpl implements IRiskFacade{
   private static RiskFacadeImpl instance = new RiskFacadeImpl();

    public static RiskFacadeImpl getInstance() {
        return instance;
    }
    public List<RiskOverview> getAllRiskOverview() {
        List<RiskGroup> groups=DAOBean.riskGroupDAO.getAllRiskGroup();
        List<RiskOverview> resultList=new ArrayList<RiskOverview>();
        for (RiskGroup group:groups){
            List<Risk> risks=DAOBean.riskDAO.getRisksByGroupId(group.getId());
            for(Risk risk:risks){
                resultList.add(new RiskOverview(risk,group));
            }
        }
        return resultList;
    }


    public Risk getRiskByName(String name) {
         return DAOBean.riskDAO.getByName(name);
    }
}
